package com.utm.gameoka;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ListaAdapter extends BaseAdapter {

	private Activity activity;
	private List<UsuarioModel> data;
	private static LayoutInflater inflater = null;

	public ListaAdapter(Activity actividad, List<UsuarioModel> lista) {
		activity = actividad;
		data = lista;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.user_row_componente, null);

		TextView username = (TextView) vi.findViewById(R.id.lblUsuario); // usuario
		CheckBox chkUsername = (CheckBox) vi.findViewById(R.id.chkUsuario); // checkBox
		// ImageView thumb_image=(ImageView)vi.findViewById(R.id.listImage);

		username.setText(data.get(position).getUsuario());
		// imageLoader.DisplayImage(l, thumb_image);
		final int pos = position;
		chkUsername.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				data.get(pos).setSeleccionado(isChecked);
			}
		});

		return vi;
	}

}
